package com.siren.tank.cor;

import com.siren.tank.GameObject;
import com.siren.tank.group.BaseTank;
import com.siren.tank.group.Bullet;
import com.siren.tank.group.Wall;

/**
 * @author : wangjichao
 * @description:
 * @date : 2020/8/8 10:16
 */
public class TankWallCollider implements Collider {

    @Override
    public boolean collide(GameObject o1, GameObject o2) {
        if (o1 instanceof BaseTank && o2 instanceof Wall) {
            BaseTank t = (BaseTank) o1;
            Wall w = (Wall) o2;
            if (isIntersection(t.getX(), t.getY(), BaseTank.WIDTH, BaseTank.HEIGHT,
                    w.getBeginX(), w.getBeginY(), w.getWidth(), w.getHeight())) {
                t.back();
                return false;
            }
        } else if (o1 instanceof Wall && o2 instanceof Bullet) {
            collide(o2, o1);
        }
        return true;
    }
}
